feat: Hook system for partition cleanup lifecycle#107
Draft
vmercierfr wants to merge 13 commits into
Draft
Conversation
fc2476c to
db203e7
Compare
Introduce the hook package with configuration model, validation logic, and the Runner interface that all hook runners must implement. Add pgregory.net/rapid for property-based testing and promote spf13/pflag to a direct dependency. Signed-off-by: Vincent Mercier <vmercier@gmail.com>
Add Go text/template based rendering for hook command arguments and SQL queries, allowing partition context variables to be interpolated into hook configurations at execution time. Signed-off-by: Vincent Mercier <vmercier@gmail.com>
Add resolver logic to merge global and partition-level hook configurations, with partition-level hooks taking precedence over global defaults. Signed-off-by: Vincent Mercier <vmercier@gmail.com>
Add credential extraction from PostgreSQL connection URLs, parsing host, database, username, and password into environment variables for use by shell hooks with propagate-credentials enabled. Signed-off-by: Vincent Mercier <vmercier@gmail.com>
Add MetricsCollector to track hook execution outcomes (success, failure, skip counts) and Registry that maps hook types to their Runner implementations. Signed-off-by: Vincent Mercier <vmercier@gmail.com>
Implement the shell hook runner that executes external commands with templated arguments, environment variable propagation, timeout handling, and configurable working directory. Signed-off-by: Vincent Mercier <vmercier@gmail.com>
Implement the PostgreSQL hook runner that executes SQL statements directly against the database with templated queries, connection management, and timeout support. Signed-off-by: Vincent Mercier <vmercier@gmail.com>
Add the Executor that drives hook Runner implementations with retry logic, on_failure policy enforcement (continue vs abort), and dry-run mode that previews which hooks would run without executing them. Signed-off-by: Vincent Mercier <vmercier@gmail.com>
Add the Orchestrator that coordinates hook lifecycle execution around partition operations (pre/post hooks), manages template context injection, and delegates to the Executor for actual hook runs. Signed-off-by: Vincent Mercier <vmercier@gmail.com>
Prepare the application layer for hooks integration: - Add Hooks field to app config and partition configuration - Add hook validation in config.Check() - Extend PPM struct with connectionURL, globalHooks, and dryRun - Add --dry-run flag to run and cleanup commands - Update existing tests for new PPM constructor signature Signed-off-by: Vincent Mercier <vmercier@gmail.com>
Wire hooks into the cleanup workflow: - Add hook helper methods (runHook, newHookOrchestrator, buildPartitionContext) - Execute pre/post hooks around partition detach and drop operations - Support on_failure policies (abort vs continue) per partition - Add comprehensive tests for hook execution and dry-run mode Signed-off-by: Vincent Mercier <vmercier@gmail.com>
Add user-facing documentation for the hooks feature: - Hook configuration reference (shell and postgresql types) - Update mkdocs navigation and CLI reference - Update README with hooks feature mention Signed-off-by: Vincent Mercier <vmercier@gmail.com>
Add developer documentation explaining how to implement new hook types, with architecture overview and step-by-step guide. Signed-off-by: Vincent Mercier <vmercier@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a requirements specification for a hook system that allows users to execute custom commands before and after partition archival operations (detach/drop).
The primary use case is archiving partition data (e.g., to S3) before dropping partitions, but the system is designed to be generic enough to support any pre/post operation workflow.
Specification
The full requirements document is available at:
.kiro/specs/partition-hooks/requirements.mdKey Design Decisions
Hook Types (initial implementation)
shell— Execute arbitrary commands with template variables and optional credential propagationpostgresql— Execute SQL statements (e.g., VACUUM, ANALYZE) using PPM database connectionHook Types (future)
s3— PPM-managed extraction pipeline with two modes:streaming(preferred): direct pipe to S3 multipart upload, no local disk usagetemp_dir(fallback): local write + upload with disk space validation usingpg_table_sizeand configurablespare_percentaws_s3— Server-side export via PostgreSQLaws_s3extension (recommended for large datasets)Lifecycle Events
before-detach,after-detach,before-drop,after-dropConfiguration Scope
Production-Ready Features
abort(stop everything) orcontinue, with safe defaults (before-hooks cancel operation, after-hooks log and continue){{.Schema}},{{.Table}},{{.ParentTable}},{{.LowerBound}},{{.UpperBound}},{{.DatabaseName}},{{.Hostname}}, etc.PGHOST,PGPORT,PGDATABASE,PGUSER,PGPASSWORDfor shell hooks--dry-runflag to preview resolved hooks without executionWhat This PR Does NOT Include
Example Configuration